package com.wuliu.driver.controller;

import com.wuliu.driver.pojo.Car;
import com.wuliu.driver.pojo.Orders;
import com.wuliu.driver.service.CarService;
import com.wuliu.driver.util.Code;
import com.wuliu.driver.util.Result;
import com.wuliu.driver.util.UploadImg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/car")
public class CarController {
    @Autowired
    private UploadImg uploadImg;
    @Autowired
    private CarService carService;
    //上传车辆图片
    @RequestMapping("/upload")
    public Result upload(MultipartFile file) throws IOException {
        String upload = uploadImg.upload(file);
        return new Result(Code.GET_OK,upload,"上传成功");
    }
    //提交审核
    @RequestMapping("/ins")
    public Result ins(@RequestBody Car car) {
        return carService.ins(car);
    }
    @RequestMapping("/cha/{id}")
    public Result cha(@PathVariable Integer id) {
        List<Car> che = carService.che(id);
        return new Result(Code.GET_OK,che,"查询成功");
    }
    //查询该用户的车辆信息
    @GetMapping("/select/{id}")
    public Result select(@PathVariable Integer id) {
        return carService.cha(id);
    }
    @RequestMapping("/yundan/{id}")
    public Result yundan(@PathVariable Integer id) {
        List<Orders> yun = carService.yun(id);
        return new Result(Code.GET_OK,yun,"查询成功");
    }
}
